package ar.org.sstuyv

import org.springframework.dao.DataIntegrityViolationException

class TipoTramiteIIUUController {

    static allowedMethods = [save: "POST", update: "POST", delete: "POST"]

    def index() {
        redirect(action: "list", params: params)
    }

    def list(Integer max) {
        params.max = Math.min(max ?: 10, 100)
        [tipoTramiteIIUUInstanceList: TipoTramiteIIUU.list(params), tipoTramiteIIUUInstanceTotal: TipoTramiteIIUU.count()]
    }

    def create() {
        [tipoTramiteIIUUInstance: new TipoTramiteIIUU(params)]
    }

    def save() {
        def tipoTramiteIIUUInstance = new TipoTramiteIIUU(params)
        if (!tipoTramiteIIUUInstance.save(flush: true)) {
            render(view: "create", model: [tipoTramiteIIUUInstance: tipoTramiteIIUUInstance])
            return
        }

        flash.message = message(code: 'default.created.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), tipoTramiteIIUUInstance.id])
        redirect(action: "show", id: tipoTramiteIIUUInstance.id)
    }

    def show(Long id) {
        def tipoTramiteIIUUInstance = TipoTramiteIIUU.get(id)
        if (!tipoTramiteIIUUInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), id])
            redirect(action: "list")
            return
        }

        [tipoTramiteIIUUInstance: tipoTramiteIIUUInstance]
    }

    def edit(Long id) {
        def tipoTramiteIIUUInstance = TipoTramiteIIUU.get(id)
        if (!tipoTramiteIIUUInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), id])
            redirect(action: "list")
            return
        }

        [tipoTramiteIIUUInstance: tipoTramiteIIUUInstance]
    }

    def update(Long id, Long version) {
        def tipoTramiteIIUUInstance = TipoTramiteIIUU.get(id)
        if (!tipoTramiteIIUUInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), id])
            redirect(action: "list")
            return
        }

        if (version != null) {
            if (tipoTramiteIIUUInstance.version > version) {
                tipoTramiteIIUUInstance.errors.rejectValue("version", "default.optimistic.locking.failure",
                          [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU')] as Object[],
                          "Another user has updated this TipoTramiteIIUU while you were editing")
                render(view: "edit", model: [tipoTramiteIIUUInstance: tipoTramiteIIUUInstance])
                return
            }
        }

        tipoTramiteIIUUInstance.properties = params

        if (!tipoTramiteIIUUInstance.save(flush: true)) {
            render(view: "edit", model: [tipoTramiteIIUUInstance: tipoTramiteIIUUInstance])
            return
        }

        flash.message = message(code: 'default.updated.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), tipoTramiteIIUUInstance.id])
        redirect(action: "show", id: tipoTramiteIIUUInstance.id)
    }

    def delete(Long id) {
        def tipoTramiteIIUUInstance = TipoTramiteIIUU.get(id)
        if (!tipoTramiteIIUUInstance) {
            flash.message = message(code: 'default.not.found.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), id])
            redirect(action: "list")
            return
        }

        try {
            tipoTramiteIIUUInstance.delete(flush: true)
            flash.message = message(code: 'default.deleted.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), id])
            redirect(action: "list")
        }
        catch (DataIntegrityViolationException e) {
            flash.message = message(code: 'default.not.deleted.message', args: [message(code: 'tipoTramiteIIUU.label', default: 'TipoTramiteIIUU'), id])
            redirect(action: "show", id: id)
        }
    }
	
	
	
	def tipoTramite = {
		
		def lst = TipoTramiteIIUU.findAll()
		
			StringBuffer buf = new StringBuffer("<select>")
			buf.append("<option value=\"${-1}\">")
			buf.append("")
			lst.each{
				buf.append("<option value=\"${it.id}\">")
				buf.append(it.toString())
				buf.append("</option>")
			}
			buf.append("</select>")
		
			render buf.toString()
	}
}
